The present invention generally relates to instrumentation of computer program code, and more particularly to profiling execution characteristics of a binary executable program having branches through stub code segments.
Executable computer programs include branch instructions that when executed direct program control to target addresses in the program. In some cases, branch instructions are used to transfer control to a code segment that implements a source-code defined function. For example, if the source code sets forth a xe2x80x9cfunctionxe2x80x9d that averages an input list of values, the function may be invoked by name in the source code. The executable code includes a target code segment that implements the function and branch instructions having target addresses that reference the target code segment. It will be appreciated that different languages have different names for functions such as procedure, routine, or method.
Binary executable programs are xe2x80x9cinstrumentedxe2x80x9d or xe2x80x9cprofiledxe2x80x9d to analyze program performance. The performance data that are gathered can be used to determine which source code might benefit most from improved coding. For example, if a particular function is called within a program loop and the loop is a hot spot during execution, it may be desirable to program the function in-line within the loop rather than as a function call.
A function call may either reference a target function in the same load module, or in a different load module. From the developer""s perspective, the source code does not reference load modules. Where a function call references a function in another load module, the code generation and linking phase establishes a stub code segment that is targeted by a first branch instruction. The stub code segment obtains the address of the entry point of the target function in the other load module and then branches to the target. Since the stub code segments are typically not directly associated with any particular lines of the source code, the correlation of execution profile information with the source code can be difficult.
A method and apparatus that address the aforementioned problems, as well as other related problems, are therefore desirable.
The invention provides profiling of branches that pass through stub code segments in executable program code. The compilation and linking of a computer program sometimes generates stub code segments that implement the transfer of control to functions that are external to a local segment of code. Branches through the stub code segments hinder the analysis of the corresponding edges relative to the source code. In various embodiments of the invention, edges are created to represent respective branch instructions in the executable program code. Each edge has a source attribute, a target attribute, and an edge-taken count attribute. During execution, the numbers of times edges are taken are counted, and stub entry points and stub targets are identified. For each edge having a target that matches an entry point of a stub code segment, the edge target is changed to the stub target associated with the matching entry point. By identifying edges that target stub code segments, edges that target stub code segments can be combined with other edges for correlation with the source code.
Various example embodiments are set forth in the Detailed Description and Claims which follow.